package api.homework.one;

import java.util.concurrent.ExecutionException;
import java.util.concurrent.FutureTask;

/**
 * @author lwj
 * @date 2025-03-10
 * @vesion 1.0.0
 */
public class MainTest {
    public static void main(String[] args) {
        // Callable 实现类
        SumOneCallable sumOneCallable = new SumOneCallable();
        SumTwoCallable sumTwoCallable = new SumTwoCallable();
        SumThreeCallable sumThreeCallable = new SumThreeCallable();

        FutureTask<Integer> futureTask1 = new FutureTask<>(sumOneCallable);
        FutureTask<Integer> futureTask2 = new FutureTask<>(sumTwoCallable);
        FutureTask<Integer> futureTask3 = new FutureTask<>(sumThreeCallable);

        Thread thread1 = new Thread(futureTask1);
        Thread thread2 = new Thread(futureTask2);
        Thread thread3 = new Thread(futureTask3);

        thread1.start();
        thread2.start();
        thread3.start();

        int sum1 = 0;
        try {
            sum1 += futureTask1.get();
            sum1 += futureTask2.get();
            sum1 += futureTask3.get();
        } catch (InterruptedException e) {
            throw new RuntimeException(e);
        } catch (ExecutionException e) {
            throw new RuntimeException(e);
        }

        System.out.println(sum1);
    }
}
